var _remoteUser = null;

function RemoteUser (table_number, callbackObject) {
  this.callbackObject = callbackObject;
  this.table_number = table_number;
  _remoteUser = this;
  _remoteUser.updateUserStatus();
  this.intervalId = window.setInterval("_remoteUser.updateUserStatus()", 60000);
} 
	
RemoteUser.prototype.updateUserStatus = function() {
    var url = "/updateUserStatus";
    if (this.table_number != null && this.table_number > 0) {
      url += "?table=" + this.table_number;
    }
    downloadUrl(url, "GET", null, onUpdateUserStatus);
}    

// static
onUpdateUserStatus = function(response) {
   response = parseResponse(response);
   if (response.users == null || response.users.length == 0) {
     if (this.intervalId != null) {
       window.clearInterval(this.intervalId);
       this.intervalId = null;
     }
   } else {  
     _remoteUser.callbackObject.updateUsers(response.users);
   }
}

